//
//  ANPicsViewController.m
//  AttitudeNews
//
//  Created by 刘晓萌 on 15/12/1.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "ANPicsViewController.h"
#import "SDCycleScrollView.h"
#import "DataHelper.h"
#import "ANPicsModel.h"
#import "UIViewController+LLT_UIViewControllerTools.h"

@interface ANPicsViewController ()<SDCycleScrollViewDelegate>

@property (strong,nonatomic)NSMutableArray *titles;
@property (strong,nonatomic)NSMutableArray *imagesURLStrings;
@property (strong,nonatomic)DataHelper *dataHelper;
@property (strong,nonatomic)NSMutableArray *dataArray;



@end


@implementation ANPicsViewController

/**
 * 处理model传来的值
 */
-(void)makeData{
    self.imagesURLStrings = [NSMutableArray array];
    self.titles = [NSMutableArray array];
    self.dataHelper = [[DataHelper alloc]init];
    __weak typeof(self) weakSelf = self;
    self.dataHelper.ResultPicsModelBlock = ^(NSMutableArray *arr){
        weakSelf.dataArray = arr;
        [weakSelf setview];
    };
    [self.dataHelper getANPicsModelBySKipId:self.newsModel.skipID];
}



/**
 * 设置布局及轮播图
 */
-(void)setview{
    for (ANPicsModel *pic in self.dataArray) {
        [self.imagesURLStrings addObject:pic.imgurl];
        [self.titles addObject:pic.note];
    }
    self.view.frame = [UIScreen mainScreen].bounds;
    self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:0.99];

    // 情景二：采用网络图片实现
    NSArray *imagesURLStrings = self.imagesURLStrings;
    // 情景三：图片配文字
    NSArray *titles = self.titles;
    CGFloat w =  self.view.frame.size.width;
    //网络加载 --- 创建带标题的图片轮播器
    SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(1, 190, w-2, 300) imageURLStringsGroup:nil];
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolStyleAnimated;
    cycleScrollView.delegate = self;
    cycleScrollView.titlesGroup = titles;
    cycleScrollView.titleLabelHeight = 100;
    //cycleScrollView.
    cycleScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder"];
    cycleScrollView.autoScrollTimeInterval = 100;//设置延迟时间
    [ self.view addSubview: cycleScrollView];
    cycleScrollView.imageURLStringsGroup = imagesURLStrings;
}

#pragma mark - SDCycleScrollViewDelegate的方法

/**
 * 轮播图的点击事件
 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    //NSLog(@"点你妹");
}
- (IBAction)didClckLeftButton:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
